<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use DB;
use App\Model\Admin\Com;


class CommentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
    	
       $comments = DB::table('comment')
                ->join('user','comment.user_id','=','user.id')
                ->join('goods','comment.goods_id','=','goods.id')
       	        ->select('comment.id','goods.goods_name','comment.content','comment.goods_id','comment.time','user.username','user.email','user.phone')
                ->get();
     
       return view('admin.comment_list')->with('comments',$comments);
    }

  	public function show($id)
    {
        /*$data1 = DB::table('user')
        ->join('orders','user.id', '=', 'orders.user_id')
        ->select('user.userusername','orders.status','orders.time')
        ->where('orders.id',$id)       
        ->first();*/
        $comment = DB::table('comment')
        ->join('user','comment.user_id','=','user.id')
        ->where('comment.id',$id)
        ->select('comment.content','comment.time','comment.reply','comment.replytime','user.username','user.email','user.phone')->first();
        return view('admin.comment_show',['comment'=>$comment]);   
    }
    public function edit($id)
    {
        $comment = DB::table('comment')
        ->join('user','comment.user_id','=','user.id')
        ->where('comment.id',$id)
        ->select('comment.content','comment.time','user.username','user.email','user.phone')->first();
        return view('admin.comment_rep',['rep'=>$comment,'id'=>$id]);
    }
    public function update(Request $request,$id)
    {
        $time = time();
        $req = DB::table('comment')->where('id',$id)->update(['reply'=>$request->rep,'replytime'=>$time]);
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function delete($id)
    {
        $res = DB::table('comment')->where('id',$id)->delete();
        return $res;
    }
}
